import java.util.Scanner;

public class Lucky {
    public static void main(String[] args) {
        //输入对象 only one
        Scanner input = new Scanner(System.in);
        //循环输出菜单
        String userSelect = null;
        String userName = null;
        String password = null;
        int cardNo = -1;
        boolean isLogin = false;
        do {
            //输出菜单
            System.out.println("*********************************");
            System.out.println("1、注册");
            System.out.println("2、登录");
            System.out.println("3、抽奖");
            System.out.println("*********************************");
            //用户选择菜单Id
            System.out.print("请选择菜单：");
            int menuId = input.nextInt();
            //根据用户的选择，输出功能模块。
            switch (menuId) {
                case 1:
                    System.out.println("抽奖系统 -> 注册");
                    //注册功能代码
                    System.out.print("请输入用户名：");
                    userName = input.next();
                    System.out.print("请输入密码：");
                    password = input.next();
                    cardNo = (int) (Math.random() * 10); // 0-9
                    System.out.println("请记好你的注册信息！");
                    System.out.println("用户名\t密码\t卡号");
                    System.out.println(userName + "\t" + password + "\t" + cardNo);
                    break;
                case 2:
                    System.out.println("抽奖系统 -> 登录");
                    //登录功能代码
                    System.out.print("请输入用户名：");
                    String name = input.next();
                    System.out.print("请输入密码：");
                    String pass = input.next();
                    if (userName.equals(name) && password.equals(pass)) {
                        System.out.println("欢迎您：" + userName);
                        isLogin = true;
                    } else {
                        System.out.println("输入错误，请重新登录！");
                    }
                    //System.exit(0);
                    break;
                case 3:
                    System.out.println("抽奖系统 -> 抽奖");
                    //判断是否登录
                    if (!isLogin) {
                        System.out.println("请先登录再抽奖！");
                        break;
                    }
                    // 第一种调用 void createCards(int[] cards)
//                    int[] cards = new int[5];
//                    createCards(cards);

                    // 第二种调用 int[] createCards(int len)
                    int [] cards = createCards(5);
                    //输出卡号
                    String msg = "幸运卡号：";
                    for (int i = 0; i < cards.length; i++) {
                        msg += cards[i] + "\t";
                    }
                    System.out.println(msg);
                    //判断是否中奖
                    boolean flag = false;
                    for (int i = 0; i < cards.length; i++) {
                        if (cards[i] == cardNo) {
                            flag = true;
                            break;
                        }
                    }
                    if (flag) {
                        System.out.println("恭喜你！");
                    } else {
                        System.out.println("sorry!");
                    }
                    break;
                default:
                    System.out.println("您的输入有误！");
                    break;
            }
            //询问是否继续
            System.out.println("继续吗？(Y/N)");
            userSelect = input.next();
        } while (userSelect.equalsIgnoreCase("y"));
        //退出系统
        System.out.println("系统退出，谢谢使用！");
    }

    //值传递和引用传递
    public static void createCards(int[] cards){
        for (int i = 0; i < cards.length; i++) {
            cards[i] = (int) (Math.random() * 10);
        }
    }

    //赋值&深拷贝&浅拷贝
    public static int[] createCards(int len){
        int [] cards = new int[len];
        for (int i = 0; i < cards.length; i++) {
            cards[i] = (int) (Math.random() * 10);
        }
        return cards;
    }
}
